// components/add-form/index.js
import {addFormDataStorage} from "../../utils/hooks"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show:{
      type:Boolean,
    },
    formData:{
      type:Object
    },
    isBuy:{
      type:Boolean,
      value:false
    },
    btnTitle:{
      type:String,
      value:"加入购物车"
    },
    saveStorage:{// 是否把表单数据保存在本地存储
      type:Boolean,
      value:true
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
  },
  lifetimes:{

  },
  /**
   * 组件的方法列表
   */
  methods: {
    modifyFormData(e) {
      // const {val,index,formList} = e.detail
      const {formData} = this.data
      // this.data.formData.list[index].value = val
      formData.list = e.detail.formList[0]
      this.setData({
        formData
      })
    },
    addCart(){
      if (!this.selectComponent("#custom-form").validate())return
      const {saveStorage,formData} = this.data
      saveStorage&&addFormDataStorage(formData)
      this.triggerEvent("addCart",{formData})
      this.setData({
        show: false
      })
    },
    close() {
      setTimeout(()=>{
        this.setData({
          show: false
        })
      },400)
     
    },
  }
})
